package com.lvmama.pangolin.controller;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.lvmama.pangolin.entity.mt.MTTicketCommodityItem;
import com.lvmama.pangolin.entity.mt.MTTicketProduct;
import com.lvmama.pangolin.mt.service.MTTicketCommodityItemsService;
import com.lvmama.pangolin.mt.service.MTTicketProductService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.lvmama.pangolin.HBaseQueryPrice.HBaseHotelHistoryPrice;
import com.lvmama.pangolin.HBaseQueryPrice.HBaseTicketHistoryPrice;
import com.lvmama.pangolin.busi.config.ConfigManager;
import com.lvmama.pangolin.common.Constant;
import com.lvmama.pangolin.entity.CommodityConditionVO;
import com.lvmama.pangolin.entity.ProductConditionVO;
import com.lvmama.pangolin.entity.RelevanceProduct;
import com.lvmama.pangolin.entity.hotel.HotelProductDetail;
import com.lvmama.pangolin.entity.link.TicketCommodityLink;
import com.lvmama.pangolin.entity.link.TicketProductLinkView;
import com.lvmama.pangolin.entity.lmm.LMMTicketCommodity;
import com.lvmama.pangolin.entity.lmm.LMMTicketProduct;
import com.lvmama.pangolin.entity.qnr.QNRTicketCommodityItem;
import com.lvmama.pangolin.entity.qnr.QNRTicketProduct;
import com.lvmama.pangolin.entity.tc.TCTicketProduct;
import com.lvmama.pangolin.entity.tc.TCommodityItem;
import com.lvmama.pangolin.entity.tn.TNTicketCommodityItem;
import com.lvmama.pangolin.entity.tn.TNTicketProduct;
import com.lvmama.pangolin.entity.xc.XCTicketCommodityItem;
import com.lvmama.pangolin.entity.xc.XCTicketProduct;
import com.lvmama.pangolin.hotel.service.HotelProductDetailService;
import com.lvmama.pangolin.lmm.service.LMMTicketCommodityService;
import com.lvmama.pangolin.lmm.service.LMMTicketProductService;
import com.lvmama.pangolin.qnr.service.QNRTicketCommodityItemsService;
import com.lvmama.pangolin.qnr.service.QNRTicketProductService;
import com.lvmama.pangolin.service.CityService;
import com.lvmama.pangolin.service.RelevanceCommodityService;
import com.lvmama.pangolin.service.RelevanceProductService;
import com.lvmama.pangolin.tc.service.TCCommodityItemsService;
import com.lvmama.pangolin.tc.service.TCTicketProductService;
import com.lvmama.pangolin.tn.service.TNTicketCommodityItemsService;
import com.lvmama.pangolin.tn.service.TNTicketProductService;
import com.lvmama.pangolin.xc.service.XCTicketCommodityItemsService;
import com.lvmama.pangolin.xc.service.XCTicketProductService;

@Controller
@RequestMapping("/datashow")
public class ShowController {
	@Autowired
	private RelevanceProductService relevanceProductService;
	@Autowired
	private LMMTicketProductService lProductService;
	@Autowired
	private XCTicketProductService xcProductService;
	@Autowired
	private TNTicketProductService tnProductService;
	@Autowired
	private TCTicketProductService tcProductService;
	@Autowired
	private QNRTicketProductService qnrProductService;

	//新增美团
	@Autowired
	private MTTicketProductService mtProductService;
	@Autowired
	private HBaseHotelHistoryPrice historyHotelPrice;
	@Autowired
	private HBaseTicketHistoryPrice historyTicketPrice;
	@Autowired
	private CityService cityService;
	@Autowired
	private LMMTicketCommodityService lmmCommodityService;
	@Autowired
	private XCTicketCommodityItemsService xcCommodityService;
	@Autowired
	private TNTicketCommodityItemsService tnCommodityService;
	@Autowired
	private TCCommodityItemsService tcCommodityService;
	@Autowired
	private QNRTicketCommodityItemsService qnrCommodityService;

	@Autowired
	private MTTicketCommodityItemsService mtCommodityService;
	@Autowired
	private RelevanceCommodityService relevanceCommodityService;
	@Autowired
	private HotelProductDetailService hotelProductService;
	/**
	 * 产品展示
	 * @param model
	 * @param pc
	 * @return
	 */
	@RequestMapping("/show_list")
	public String showList(ModelMap model,ProductConditionVO pc){
		/**
		 * 查询所有已经关联的产品
		 */
		PageInfo<RelevanceProduct> page=relevanceProductService.viewAllRelevance(pc);
		List<RelevanceProduct> relProducts=page.getList();
		ConfigManager config = ConfigManager.getInstance();
		double priceRange =  Double.valueOf(config.getParamValue("show_price_range", "SHOW_PRICE_RANGE","0"));
		String snapshot_url=config.getParamValue("snapshot_url", "SNAPSHOT_URL");
		/**
		 * 产品展示信息，每条记录为一个TicketProductLink对象
		 */
		List<TicketProductLinkView> tprodList=new  ArrayList<TicketProductLinkView>();
		
		/**
		 * 遍历关联产品列表，根据每一条关联信息，返回一条页面展示信息
		 */

		for(int i=0;i<relProducts.size();i++){
			/**
			 * 用来存放一条展示信息，作为dto
			 */
			TicketProductLinkView tpl=new TicketProductLinkView();
			/**
			 * 根据productId获得一条已经关联的产品
			 */
			RelevanceProduct rp=relProducts.get(i);
			/**
			 * 1.根据productId,从一条产品关联记录里拿到对应lmm产品表详细信息
			 * 2.将lmm产品详细信息存入TicketProductLink中
			 */
			if(rp!=null){
				if(pc.getBusinessCode()==null||"".equals(pc.getBusinessCode())||"TICKET".equals(pc.getBusinessCode())){
					LMMTicketProduct lp=lProductService.selectByProductId(rp.getProdId());//查询ticket_product_lmm表
					tpl.setProd_id(lp.getProductId());
					tpl.setScenery_name(lp.getSceneryName());
					tpl.setCity_code(cityService.queryCityById(lp.getCityCode()).getName());
					tpl.setStar_level(lp.getStarLevel());
					tpl.setScore(lp.getScore());
					tpl.setDetail_url(lp.getDetailUrl());
					
					/**
					 * 改成用户自定义的商品价格作为产品起价
					 */
					String commodityId=lmmCommodityService.selectCommodityId(lp.getProductId());//查询ticket_commodity_lmm
					if(commodityId!=null&&!commodityId.equals("")){
						LMMTicketCommodity lmmc=lmmCommodityService.selectByProdCommId(lp.getProductId(), commodityId);
						tpl.setLowest_price(lmmc.getSalePrice()); 
					}else{
						tpl.setLowest_price(lp.getLowestPrice());
					}
					
					/**
					 * 1.根据productId,从一条产品关联记录里拿到对应xc产品表详细信息
					 * 2.将xc产品详细信息存入TicketProductLink中
					 */
					if(rp.getProdIdXC()!=null&&!rp.getProdIdXC().equals("")&&rp.getProdNameXC()!=null&&!rp.getProdNameXC().equals("")){
						XCTicketProduct xcp=xcProductService.selectByProdId(rp.getProdIdXC());
						if(xcp!=null){
							if(commodityId!=null&&!commodityId.equals("")){
								List<TicketCommodityLink> cls=relevanceCommodityService.selectByCommProdComp(lp.getProductId(), commodityId, "xc");
								if(cls.size()>0){
									XCTicketCommodityItem  xcc=xcCommodityService.selectByProdCommId(cls.get(0).getRel_prod_id(), cls.get(0).getRel_commodity_id());
									tpl.setLowest_price_xc(xcc.getSale_price());
								}else{
									tpl.setLowest_price_xc(xcp.getLowestPrice());
								}
								
							}else{
								tpl.setLowest_price_xc(xcp.getLowestPrice());
							}
							
							tpl.setProd_id_xc(xcp.getProductId());
							tpl.setScore_xc(xcp.getScore());
							if(xcp.getSnapshotAddr()!=null&&!"".equals(xcp.getSnapshotAddr().trim())){
								String[] urls=xcp.getSnapshotAddr().split("/");
								tpl.setSnapshot_addr_xc(snapshot_url+urls[urls.length-1]);
							}
							tpl.setScenery_name_xc(xcp.getSceneryName());
							tpl.setDetail_url_xc(xcp.getDetailUrl());
						}
					}
					/**
					 * 1.根据prodIdXC,从一条产品关联记录里拿到对应tn产品表详细信息
					 * 2.将tn产品详细信息存入TicketProductLink中
					 */
					if(rp.getProdIdTN()!=null&&!rp.getProdIdTN().equals("")&&rp.getProdNameTN()!=null&&!rp.getProdNameTN().equals("")){
						TNTicketProduct tnp=tnProductService.selectByProdId(rp.getProdIdTN());
						if(tnp!=null){
							if(commodityId!=null&&!commodityId.equals("")){
								List<TicketCommodityLink> cls=relevanceCommodityService.selectByCommProdComp(lp.getProductId(), commodityId, "tn");
								if(cls.size()>0){
									TNTicketCommodityItem  tnc=tnCommodityService.selectByProdCommId(cls.get(0).getRel_prod_id(), cls.get(0).getRel_commodity_id());
									tpl.setLowest_price_tn(tnc.getSale_price());
								}else{
									tpl.setLowest_price_tn(tnp.getLowestPrice());
								}
								
							}else{
								tpl.setLowest_price_tn(tnp.getLowestPrice());
							}
							
							tpl.setProd_id_tn(tnp.getProductId());
							tpl.setScore_tn(tnp.getScore());
							if(tnp.getSnapshotAddr()!=null&&!"".equals(tnp.getSnapshotAddr().trim())){
								String[] urls=tnp.getSnapshotAddr().split("/");
								tpl.setSnapshot_addr_tn(snapshot_url+urls[urls.length-1]);
							}
							tpl.setScenery_name_tn(tnp.getSceneryName());
							tpl.setDetail_url_tn(tnp.getDetailUrl());
						}
					}
					
					/**
					 * 1.根据prodIdTC,从一条产品关联记录里拿到对应tc产品表详细信息
					 * 2.将tc产品详细信息存入TicketProductLink中
					 */
					if(rp.getProdIdTC()!=null&&!rp.getProdIdTC().equals("")&&rp.getProdNameTC()!=null&&!rp.getProdNameTC().equals("")){
						TCTicketProduct tcp=tcProductService.selectByProdId(rp.getProdIdTC());
						if(tcp!=null){
							if(commodityId!=null&&!commodityId.equals("")){
								List<TicketCommodityLink> cls=relevanceCommodityService.selectByCommProdComp(lp.getProductId(), commodityId, "tc");
								if(cls.size()>0){
									TCommodityItem  tcc=tcCommodityService.selectByProdCommId(cls.get(0).getRel_prod_id(), cls.get(0).getRel_commodity_id());
									tpl.setLowest_price_tc(tcc.getSale_price());
								}else{
									tpl.setLowest_price_tc(tcp.getLowestPrice());
								}
							}else{
								tpl.setLowest_price_tc(tcp.getLowestPrice());
							}
							tpl.setProd_id_tc(tcp.getProductId());
							tpl.setScore_tc(tcp.getScore());
							if(tcp.getSnapshotAddr()!=null&&!"".equals(tcp.getSnapshotAddr().trim())){
								String[] urls=tcp.getSnapshotAddr().split("/");
								tpl.setSnapshot_addr_tc(snapshot_url+urls[urls.length-1]);
							}
							tpl.setScenery_name_tc(tcp.getSceneryName());
							tpl.setDetail_url_tc(tcp.getDetailUrl());
						}
					}
					
					/**
					 * 1.根据prodIdQNR,从一条产品关联记录里拿到对应qnr产品表详细信息
					 * 2.将qnr产品详细信息存入TicketProductLink中
					 */
					if(rp.getProdIdQNR()!=null&&!rp.getProdIdQNR().equals("")&&rp.getProdNameQNR()!=null&&!rp.getProdNameQNR().equals("")){
						QNRTicketProduct qnrp=qnrProductService.selectByProdId(rp.getProdIdQNR());
						if(qnrp!=null){
							if(commodityId!=null&&!commodityId.equals("")){
								List<TicketCommodityLink> cls=relevanceCommodityService.selectByCommProdComp(lp.getProductId(), commodityId, "qnr");
								if(cls.size()>0){
									QNRTicketCommodityItem  qnrc=qnrCommodityService.selectByProdCommId(cls.get(0).getRel_prod_id(), cls.get(0).getRel_commodity_id());
									tpl.setLowest_price_qnr(qnrc.getSale_price());
								}else{
									tpl.setLowest_price_qnr(qnrp.getLowestPrice());
								}
							}else{
								tpl.setLowest_price_qnr(qnrp.getLowestPrice());
							}
							tpl.setProd_id_qnr(qnrp.getProductId());
							tpl.setScore_qnr(qnrp.getScore());
							if(qnrp.getSnapshotAddr()!=null&&!"".equals(qnrp.getSnapshotAddr().trim())){
								String[] urls=qnrp.getSnapshotAddr().split("/");
								tpl.setSnapshot_addr_qnr(snapshot_url+urls[urls.length-1]);
							}
							tpl.setScenery_name_qnr(qnrp.getSceneryName());
							tpl.setDetail_url_qnr(qnrp.getDetailUrl());
						}
					}


					/**
					 * 1.根据prodIdMT,从一条产品关联记录里拿到对应mt产品表详细信息
					 * 2.将qnr产品详细信息存入TicketProductLink中
					 */
					if(rp.getProdIdMT()!=null&&!"".equals(rp.getProdIdMT())&&rp.getProdNameMT()!=null&&!"".equals(rp.getProdNameMT())){
						MTTicketProduct mtp=mtProductService.selectByProdId(rp.getProdIdMT());
						if(mtp!=null){
							if(commodityId!=null&&!commodityId.equals("")){
								List<TicketCommodityLink> cls=relevanceCommodityService.selectByCommProdComp(lp.getProductId(), commodityId, "mt");
								if(cls.size()>0){//查询表ticket_pdetial_mt表
									MTTicketCommodityItem mtc=mtCommodityService.selectByProdCommId(cls.get(0).getRel_prod_id(), cls.get(0).getRel_commodity_id());
									tpl.setLowest_price_mt(mtc.getSale_price());
								}else{
									tpl.setLowest_price_mt(mtp.getLowestPrice());
								}
							}else{
								tpl.setLowest_price_mt(mtp.getLowestPrice());
							}
							tpl.setProd_id_mt(mtp.getProductId());
							tpl.setScore_mt(mtp.getScore());
							if(mtp.getSnapshotAddr()!=null&&!"".equals(mtp.getSnapshotAddr().trim())){
								String[] urls=mtp.getSnapshotAddr().split("/");
								tpl.setSnapshot_addr_mt(snapshot_url+urls[urls.length-1]);
							}
							tpl.setScenery_name_mt(mtp.getSceneryName());
							tpl.setDetail_url_mt(mtp.getDetailUrl());
						}
					}

				}else if("HOTEL".equals(pc.getBusinessCode())){
					HotelProductDetail lmmProd=hotelProductService.findByProductId(rp.getProdId(),"LMM_C_CODE");
					tpl.setProd_id(lmmProd.getProductId());
					tpl.setScenery_name(lmmProd.getHotelName());
					tpl.setCity_code(cityService.queryCityById(lmmProd.getCityCode()).getName());
					tpl.setStar_level(lmmProd.getStarLevel());
					tpl.setScore(lmmProd.getScore());
					tpl.setDetail_url(lmmProd.getDetailUrl());
					tpl.setLowest_price(lmmProd.getLowestPrice());
					HotelProductDetail xcp=hotelProductService.findByProductId(rp.getProdIdXC(),"XC_C_CODE");
					HotelProductDetail tnp=hotelProductService.findByProductId(rp.getProdIdTN(),"TN_C_CODE");
					HotelProductDetail tcp=hotelProductService.findByProductId(rp.getProdIdTC(),"TC_C_CODE");
					HotelProductDetail qnrp=hotelProductService.findByProductId(rp.getProdIdQNR(),"QNR_C_CODE");
					HotelProductDetail elp=hotelProductService.findByProductId(rp.getProdIdEL(),"EL_C_CODE");
					HotelProductDetail mtp=hotelProductService.findByProductId(rp.getProdIdMT(),"MT_C_CODE");//增加美团
					if(xcp!=null){
						tpl.setProd_id_xc(xcp.getProductId());
						tpl.setScore_xc(xcp.getScore());
						tpl.setLowest_price_xc(xcp.getLowestPrice());
						if(xcp.getSnapshotAddr()!=null&&!"".equals(xcp.getSnapshotAddr().trim())){
							String[] urls=xcp.getSnapshotAddr().split("/");
							tpl.setSnapshot_addr_xc(snapshot_url+urls[urls.length-1]);
						}
						tpl.setScenery_name_xc(xcp.getHotelName());
						tpl.setDetail_url_xc(xcp.getDetailUrl());
					}
					if(tcp!=null){
						tpl.setProd_id_tc(tcp.getProductId());
						tpl.setScore_tc(tcp.getScore());
						tpl.setLowest_price_tc(tcp.getLowestPrice());
						if(tcp.getSnapshotAddr()!=null&&!"".equals(tcp.getSnapshotAddr().trim())){
							String[] urls=tcp.getSnapshotAddr().split("/");
							tpl.setSnapshot_addr_tc(snapshot_url+urls[urls.length-1]);
						}
						tpl.setScenery_name_tc(tcp.getHotelName());
						tpl.setDetail_url_tc(tcp.getDetailUrl());
					}
					if(tnp!=null){
						tpl.setProd_id_tn(tnp.getProductId());
						tpl.setScore_tn(tnp.getScore());
						tpl.setLowest_price_tn(tnp.getLowestPrice());
						if(tnp.getSnapshotAddr()!=null&&!"".equals(tnp.getSnapshotAddr().trim())){
							String[] urls=tnp.getSnapshotAddr().split("/");
							tpl.setSnapshot_addr_tn(snapshot_url+urls[urls.length-1]);
						}
						tpl.setScenery_name_tn(tnp.getHotelName());
						tpl.setDetail_url_tn(tnp.getDetailUrl());
					}
					if(qnrp!=null){
						tpl.setProd_id_qnr(qnrp.getProductId());
						tpl.setScore_qnr(qnrp.getScore());
						tpl.setLowest_price_qnr(qnrp.getLowestPrice());
						if(qnrp.getSnapshotAddr()!=null&&!"".equals(qnrp.getSnapshotAddr().trim())){
							String[] urls=qnrp.getSnapshotAddr().split("/");
							tpl.setSnapshot_addr_qnr(snapshot_url+urls[urls.length-1]);
						}
						tpl.setScenery_name_qnr(qnrp.getHotelName());
						tpl.setDetail_url_qnr(qnrp.getDetailUrl());
					}
					if(elp!=null){
						tpl.setProd_id_el(elp.getProductId());
						tpl.setScore_el(elp.getScore());
						tpl.setLowest_price_el(elp.getLowestPrice());
						if(elp.getSnapshotAddr()!=null&&!"".equals(elp.getSnapshotAddr().trim())){
							String[] urls=elp.getSnapshotAddr().split("/");
							tpl.setSnapshot_addr_el(snapshot_url+urls[urls.length-1]);
						}
						tpl.setScenery_name_el(elp.getHotelName());
						tpl.setDetail_url_el(elp.getDetailUrl());
					}
					/**
					 * 美团支持酒店后改业务逻辑成立，目前暂时未支持酒店
					 */
//					if(mtp!=null){
//						tpl.setProd_id_mt(mtp.getProductId());
//						tpl.setScore_mt(mtp.getScore());
//						tpl.setLowest_price_mt(mtp.getLowestPrice());
//						if(mtp.getSnapshotAddr()!=null&&!"".equals(mtp.getSnapshotAddr().trim())){
//							String[] urls=mtp.getSnapshotAddr().split("/");
//							tpl.setSnapshot_addr_mt(snapshot_url+urls[urls.length-1]);
//						}
//						tpl.setScenery_name_el(mtp.getHotelName());
//						tpl.setDetail_url_el(mtp.getDetailUrl());
//					}
				}
				
				
				tprodList.add(tpl);
			}
		}
		model.addAttribute("priceRange", priceRange);
		model.addAttribute("productConditionVO", pc);
		model.addAttribute("tprodList", tprodList);
		model.addAttribute("page", page);
		
		return "/datashow/show_list";
	}
	
	/**
	 * 异步请求历史产品价格
	 * @param productId
	 * @return
	 */
	@RequestMapping("/productPriceHistory")
	@ResponseBody
	public Object productPriceHistory(String productId,String businessCode){
		Map<String, Object> result = getResult();
		/**
		 * 酒店产品历史价格rowkey要更改
		 */
		/**
		 * 根据productId获取关联信息
		 */
		RelevanceProduct  rp=relevanceProductService.viewRelevance(productId,businessCode);
		if(businessCode==null||"".equals(businessCode)||"TICKET".equals(businessCode)){
			if(rp!=null&&rp.getProdId()!=null){
				/**
				 * 根据productId拿到lmm历史列表并进行排序
				 */
				String tableNamel=Constant.TICKET_PRODUCT_H_LMM;
				String family=Constant.HB_VARIABLE_FAMILY;
				List<Map<String,String>> lmmList=historyTicketPrice.queryByRange(rp.getProdId(), tableNamel,family);
				Collections.sort(lmmList,new Comparator<Map<String,String>>() {
					@Override
					public int compare(Map<String, String> o1, Map<String, String> o2) {
						return o2.get("insert_time").compareTo(o1.get("insert_time"));
					}
					
				});
				if(lmmList.size()>0&&lmmList.size()<2){
					result.put("lmmList",null);
				}else if(lmmList.size()>=2&&lmmList.size()<4){
					result.put("lmmList",lmmList.subList(1, lmmList.size()));
				}else if(lmmList.size()>=4){
					result.put("lmmList",lmmList.subList(1, 4));
				}
				
				/**
				 * 根据productId拿到xc历史列表并进行排序
				 */
				if(rp.getProdIdXC()!=null){
					String tableNamex=Constant.TICKET_PRODUCT_H_XC;
					List<Map<String,String>> xcList=historyTicketPrice.queryByRange(rp.getProdIdXC(), tableNamex,family);
					Collections.sort(xcList,new Comparator<Map<String,String>>() {
						@Override
						public int compare(Map<String, String> o1, Map<String, String> o2) {
							return o2.get("create_time").compareTo(o1.get("create_time"));
						}
						
					});
					if(xcList.size()>0&&xcList.size()<2){
					result.put("xcList",null);
					}else if(xcList.size()>=2&&xcList.size()<4){
						result.put("xcList",xcList.subList(1, xcList.size()));
					}else if(xcList.size()>=4){
						result.put("xcList",xcList.subList(1, 4));
					}
				}
				/**
				 * 根据productId拿到tn历史列表并进行排序
				 */
				if(rp.getProdIdTN()!=null){
					String tableNamen=Constant.TICKET_PRODUCT_H_TN;
					List<Map<String,String>> tnList=historyTicketPrice.queryByRange(rp.getProdIdTN(), tableNamen,family);
					Collections.sort(tnList,new Comparator<Map<String,String>>() {
						@Override
						public int compare(Map<String, String> o1, Map<String, String> o2) {
							return o2.get("create_time").compareTo(o1.get("create_time"));
						}
						
					});
					if(tnList.size()>0&&tnList.size()<2){
						result.put("tnList",null);
					}else if(tnList.size()>=2&&tnList.size()<4){
							result.put("tnList",tnList.subList(1, tnList.size()));
					}else if(tnList.size()>=4){
							result.put("tnList",tnList.subList(1, 4));
					}
				}
				/**
				 * 根据productId拿到tc历史列表并进行排序
				 */
				if(rp.getProdIdTC()!=null){
					String tableNamec=Constant.TICKET_PRODUCT_H_TC;
					List<Map<String,String>> tcList=historyTicketPrice.queryByRange(rp.getProdIdTC(), tableNamec,family);
					Collections.sort(tcList,new Comparator<Map<String,String>>() {
						@Override
						public int compare(Map<String, String> o1, Map<String, String> o2) {
							return o2.get("create_time").compareTo(o1.get("create_time"));
						}
						
					});
					if(tcList.size()>0&&tcList.size()<2){
						result.put("tcList",null);
					}else if(tcList.size()>=2&&tcList.size()<4){
							result.put("tcList",tcList.subList(1, tcList.size()));
					}else if(tcList.size()>=4){
							result.put("tcList",tcList.subList(1, 4));
					}
				}
				/**
				 * 根据productId拿到qnr历史列表并进行排序
				 */
				if(rp.getProdIdQNR()!=null){
					String tableNameq=Constant.TICKET_PRODUCT_H_QNR;
					List<Map<String,String>> qnrList=historyTicketPrice.queryByRange(rp.getProdIdQNR(), tableNameq,family);
					Collections.sort(qnrList,new Comparator<Map<String,String>>() {
						@Override
						public int compare(Map<String, String> o1, Map<String, String> o2) {
							return o2.get("create_time").compareTo(o1.get("create_time"));
						}
						
					});
					if(qnrList.size()>0&&qnrList.size()<2){
						result.put("qnrList",null);
					}else if(qnrList.size()>=2&&qnrList.size()<4){
							result.put("qnrList",qnrList.subList(1, qnrList.size()));
					}else if(qnrList.size()>=4){
							result.put("qnrList",qnrList.subList(1, 4));
					}
				}

				/**
				 * 新增美团的历史价格详情
				 * 根据productId拿到美团历史列表并进行排序
				 */
				if(rp.getProdIdMT()!=null){
//					String tableNameq=Constant.TICKET_PRODUCT_H_QNR;//美团产品历史表，由于表中没有数据切换可以-使用去哪儿的产品历史表-进行测试
					String tableNameq=Constant.TICKET_PRODUCT_H_MT;//美团产品历史表
					List<Map<String,String>> mtList=historyTicketPrice.queryByRange(rp.getProdIdMT(), tableNameq,family);//根据美团产品ID，表名查询
					if(mtList!=null&&mtList.size()>0){
						Collections.sort(mtList,new Comparator<Map<String,String>>() {
							@Override
							public int compare(Map<String, String> o1, Map<String, String> o2) {
								if(o1==null || StringUtils.isEmpty(o1.get("create_time")))
									return -1;
								if(o2==null || StringUtils.isEmpty(o2.get("create_time")))
									return 1;
								return o2.get("create_time").compareTo(o1.get("create_time"));
							}

						});
					}
					if(mtList.size()>0&&mtList.size()<2){
						result.put("mtList",null);
					}else if(mtList.size()>=2&&mtList.size()<4){
						result.put("mtList",mtList.subList(1, mtList.size()));
					}else if(mtList.size()>=4){
						result.put("mtList",mtList.subList(1, 4));
					}
				}

			}
		}else if("HOTEL".equals(businessCode)){
			String tableName=Constant.HOTEL_PRODUCT_H;
			if(rp!=null&&rp.getProdId()!=null){
				/**
				 * 根据productId拿到lmm历史列表并进行排序
				 */
				List<Map<String,String>> lmmList=historyHotelPrice.queryHotelProductByRange(rp.getProdId(), "LMM",tableName);
				Collections.sort(lmmList,new Comparator<Map<String,String>>() {
					@Override
					public int compare(Map<String, String> o1, Map<String, String> o2) {
						return o2.get("updateTime").compareTo(o1.get("updateTime"));
					}
					
				});
				if(lmmList.size()>0&&lmmList.size()<2){
					result.put("lmmList",null);
				}else if(lmmList.size()>=2&&lmmList.size()<4){
					result.put("lmmList",lmmList.subList(1, lmmList.size()));
				}else if(lmmList.size()>=4){
					result.put("lmmList",lmmList.subList(1, 4));
				}
			}
			/**
			 * 根据productId拿到xc历史列表并进行排序
			 */
			if(rp!=null&&rp.getProdIdXC()!=null){
				List<Map<String,String>> xcList=historyHotelPrice.queryHotelProductByRange(rp.getProdIdXC(), "XC_C_CODE",tableName);
				Collections.sort(xcList,new Comparator<Map<String,String>>() {
					@Override
					public int compare(Map<String, String> o1, Map<String, String> o2) {
						return o2.get("updateTime").compareTo(o1.get("updateTime"));
					}
					
				});
				if(xcList.size()>0&&xcList.size()<2){
					result.put("xcList",null);
				}else if(xcList.size()>=2&&xcList.size()<4){
					result.put("xcList",xcList.subList(1, xcList.size()));
				}else if(xcList.size()>=4){
					result.put("xcList",xcList.subList(1, 4));
				}
			}
			if(rp!=null&&rp.getProdIdTN()!=null){
				/**
				 * 根据productId拿到tn历史列表并进行排序
				 */
				List<Map<String,String>> tnList=historyHotelPrice.queryHotelProductByRange(rp.getProdIdTN(), "TN_C_CODE",tableName);
				Collections.sort(tnList,new Comparator<Map<String,String>>() {
					@Override
					public int compare(Map<String, String> o1, Map<String, String> o2) {
						return o2.get("updateTime").compareTo(o1.get("updateTime"));
					}
					
				});
				if(tnList.size()>0&&tnList.size()<2){
					result.put("tnList",null);
				}else if(tnList.size()>=2&&tnList.size()<4){
					result.put("tnList",tnList.subList(1, tnList.size()));
				}else if(tnList.size()>=4){
					result.put("tnList",tnList.subList(1, 4));
				}
			}
			if(rp!=null&&rp.getProdIdTC()!=null){
				/**
				 * 根据productId拿到tc历史列表并进行排序
				 */
				List<Map<String,String>> tcList=historyHotelPrice.queryHotelProductByRange(rp.getProdIdTC(), "TC_C_CODE",tableName);
				Collections.sort(tcList,new Comparator<Map<String,String>>() {
					@Override
					public int compare(Map<String, String> o1, Map<String, String> o2) {
						return o2.get("updateTime").compareTo(o1.get("updateTime"));
					}
					
				});
				if(tcList.size()>0&&tcList.size()<2){
					result.put("tcList",null);
				}else if(tcList.size()>=2&&tcList.size()<4){
					result.put("tcList",tcList.subList(1, tcList.size()));
				}else if(tcList.size()>=4){
					result.put("tcList",tcList.subList(1, 4));
				}
			}
			if(rp!=null&&rp.getProdIdQNR()!=null){
				/**
				 * 根据productId拿到qnr历史列表并进行排序
				 */
				List<Map<String,String>> qnrList=historyHotelPrice.queryHotelProductByRange(rp.getProdIdQNR(), "QNR_C_CODE",tableName);
				Collections.sort(qnrList,new Comparator<Map<String,String>>() {
					@Override
					public int compare(Map<String, String> o1, Map<String, String> o2) {
						return o2.get("updateTime").compareTo(o1.get("updateTime"));
					}
					
				});
				if(qnrList.size()>0&&qnrList.size()<2){
					result.put("qnrList",null);
				}else if(qnrList.size()>=2&&qnrList.size()<4){
					result.put("qnrList",qnrList.subList(1, qnrList.size()));
				}else if(qnrList.size()>=4){
					result.put("qnrList",qnrList.subList(1, 4));
				}
			}
			if(rp!=null&&rp.getProdIdEL()!=null){
				/**
				 * 根据productId拿到qnr历史列表并进行排序
				 */
				List<Map<String,String>> elList=historyHotelPrice.queryHotelProductByRange(rp.getProdIdEL(), "EL_C_CODE",tableName);
				Collections.sort(elList,new Comparator<Map<String,String>>() {
					@Override
					public int compare(Map<String, String> o1, Map<String, String> o2) {
						return o2.get("updateTime").compareTo(o1.get("updateTime"));
					}
					
				});
				if(elList.size()>0&&elList.size()<2){
					result.put("elList",null);
				}else if(elList.size()>=2&&elList.size()<4){
					result.put("elList",elList.subList(1, elList.size()));
				}else if(elList.size()>=4){
					result.put("elList",elList.subList(1, 4));
				}
			}
			/**
			 * 美团暂时没有酒店列表
			 */
		}
		
		return result;
	}
	public Map<String, Object> getResult() {
    	
        Map<String, Object> result = new HashMap<String, Object>();
        
        return result;
    }
	public CommodityConditionVO getCo(){
		CommodityConditionVO co=new CommodityConditionVO();
		return co;
	}
}
